package com.zsc.wxm.ysh.anjo.house.controller;

import com.zsc.wxm.ysh.anjo.house.service.AdvertiseService;
import com.zsc.wxm.ysh.anjo.result.PageResult;
import com.zsc.wxm.ysh.anjo.result.Result;
import com.zsc.wxm.ysh.anjo.service.base.model.resources.dto.AdvertiseDTO;
import com.zsc.wxm.ysh.anjo.service.base.model.resources.qo.AdvertiseQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 描述：
 *
 * @author playmaker
 * @since 2021/3/13 1:06
 */
@RestController
@RequestMapping("/house/advertise")
public class AdvertiseController {

    @Resource
    private AdvertiseService service;

    @PostMapping("/add")
    @ApiOperation("新增")
    public Result add(@Validated AdvertiseDTO param) {
        service.add(param);
        return Result.ok("增加成功");
    }

    @PostMapping("/list-page")
    @ApiOperation("分页查询")
    public PageResult listPage(@RequestBody AdvertiseQuery query) {
        return service.listPage(query);
    }

    @GetMapping("/info/{id}")
    @ApiOperation("详情")
    public Result infoById(@PathVariable("id") Long id) {
        Map<String, Object> data = new HashMap<>(1);
        data.put("data", service.infoById(id));
        return Result.ok("获取成功", data);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public Result deleteAdvertise(@PathVariable("id") Long id) {
        service.deleteAdvertise(id);
        return Result.ok("删除成功");
    }

    @PutMapping("/update")
    @ApiOperation("更新")
    public Result updateItem(@Validated @RequestBody AdvertiseDTO param) {
        service.updateItem(param);
        return Result.ok("更新成功");
    }

    @GetMapping("/get-top-list")
    @ApiOperation("获取前五个")
    public Result getTopList() {
        Map<String, Object> data = new HashMap<>(1);
        data.put("list", service.getTopList());
        return Result.ok("获取成功", data);
    }

    @PutMapping("/update-status/{id}/{status}")
    @ApiOperation("更新状态")
    public void updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        service.updateStatus(id, status);
    }
}
